import instence from './axiosConfig';
//封装后端统一响应ResponseEntity接口：
interface ResponseEntity<T> {
    code: number;
    message: string;
    data: T;
}

//封装axios请求, 还是确认使用restful风格
//下面的内容，没有单独处理.then和.catch，等请求拦截器和相应拦截器统一处理
const http = {
    //params 处理 ?currentPage=1&pageSize=10
    //Promise 是什么对象？Promise 可以处理异步响应结果 等着，后返回后 执行.then()
    get: <T>(url: string, params?: any): Promise<ResponseEntity<T>> => {
        // new axios({method: 'get', url, params})
        return instence({
            method: 'get',
            url,
            params, //专门用来封装分页数据
        })
    },
    post: <T>(url: string, data?: any): Promise<ResponseEntity<T>> => {
        return instence({
            method: 'post',
            url,
            data, //专门用来封装新增数据
        })
    },
    put: <T>(url: string, data?: any): Promise<ResponseEntity<T>> => {
        debugger
        return instence({
            method: 'put',
            url,
            data, //专门用来封装修改数据
        })
    },
    delete: <T>(url: string, params?: any): Promise<ResponseEntity<T>> => {
        return instence({
            method: 'delete',
            url,
            params, //专门用来封装删除数据
        })
    },
}
export default http;